package com.zsrt.java.day20161226.zsh.demo02;

import java.util.Scanner;

public class CalculatorSwictch {
	
	public static void main(String[] args) {
		Scanner input=new Scanner(System.in);
		
		System.out.println("输入一个算术符号（+、-、*、/、%）：");
		String sign=input.next();
	
		System.out.println("输入第一个数字：");
		int first=input.nextInt();
		
		System.out.println("输入第二个数字：");
		int second=input.nextInt();
	
		input.close();
		
		int p=cal(sign,first,second);
		System.out.println(first+sign+second+"="+p);
	}
	
	public static int cal(String sign,int first,int second){
		int resualt=0;
		
		switch(sign){
			case "+":resualt=first+second;break;
			case "-":resualt=first-second;break;
			case "*":resualt=first*second;break;
			case "/":if(second==0){
				return 0;
			}resualt=first/second;
			break;
			case "%":if(second==0){
				return 0;
			}resualt=first%second;
			break;
		}
		return resualt;
	}
}
